package com.test;

import com.entity.Person;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class PersonBuild {
    private static Map<String, Object> getPersonMap(){
        Properties properties = new Properties();
        Map<String, Object> map = new HashMap<>();
        InputStream in = PersonBuild.class.getResourceAsStream("person.properties");
        try {
            properties.load(in);
            Set<String> strings = properties.stringPropertyNames();
            for (String string:strings) {
                String person = properties.getProperty(string);
                Object object = Class.forName(person).newInstance();
                map.put(string,object);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return map;
    }

    public static Object getPerson(String str){
        Map<String, Object> personMap = getPersonMap();

        return personMap.get(str);
    }
}
